 def tlgf(t):
    j = t
    for i in range(2, t-1, 1):
        if (t / i == int(t/i)): 
            j=i
    if j == t:
        return j
    else:
        return 0
    
b = int(input(""))

if (b >= 1000 and b <=9999 and b == int(b)):
    nop = 0
    if tlgf(b): 
        nop = b
    else:
      c1 = int(b/1000)
      c2 = int(b/100-c1*10)
      c3 = int(b/10-c1*100-c2*10)
      c4 = int(b-c1*1000-c2*100-c3*10)
      
      if tlgf(c1*10+c2)>nop:
          nop = c1*10+c2

      if tlgf(c2*10+c3)>nop:
          nop = c2*10+c3

      if tlgf(c3*10+c4)>nop:
          nop = c3*10+c4

      if tlgf(c1*100+c2*10+c3)>nop:
          nop = c1*100+c2*10+c3

      if tlgf(c2*100+c3*10+c4)>nop:
          nop = c2*100+c3*10+c4

    print(nop)
else:
    print(0)






